﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SecurityDev
{
    public partial class DVRform : Form
    {
        public DVRform()
        {
            InitializeComponent();

            dataGridView1.DataSource = DS.outpost.dvr;            
            dataGridView1.Columns["obj_seq"].HeaderText = "Object ID";
            dataGridView1.Columns["dvr_seq"].HeaderText = "DVR ID";
            dataGridView1.Columns["dvr_name"].HeaderText = "Name";
            dataGridView1.Columns["dvr_ip"].HeaderText = "DVR IP";
        }

        private void saveChBtn_Click(object sender, EventArgs e)
        {
            DS.dvrAdapter.Update(DS.outpost.dvr);
        }

        private void DonnBtn_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 1)
            {
                deleteBtn.Enabled = true;
            }
            else
            {
                deleteBtn.Enabled = false;
            }
        }

        private void deleteBtn_Click(object sender, EventArgs e)
        {
            OutpostDS.dvrRow r = DS.outpost.dvr.FindBydvr_seq((decimal)dataGridView1.SelectedRows[0].Cells[0].Value);
            foreach (var alert_perR in r.GetChildRows("alert_ibfk_1"))
            {
                alert_perR.Delete();
            }
            r.Delete();
            try
            {
                DS.alertAdapter.Update(DS.outpost.alert);
                DS.dvrAdapter.Update(DS.outpost.dvr);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
